<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + " ://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML>
<jsp:include page="root_public.jsp"/>
<title>修改权限 - 权限管理</title>
</head>

<body>
<div class="x-body">
    <form class="layui-form" action="<%=path%>/menu/save">
        <div class="layui-form-item">
            <label for="name" class="layui-form-label">
                <span class="x-red">*</span>权限名称
            </label>
            <div class="layui-input-inline">
                <input type="text" id="name" name="name" required="" lay-verify="name"
                       autocomplete="off" value="admin" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="href" class="layui-form-label">
                <span class="x-red">*</span>权限规则
            </label>
            <div class="layui-input-inline">
                <input type="text" id="href" name="href" required="" lay-verify="rule"
                       autocomplete="off" value="admin" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="sort" class="layui-form-label">
                <span class="x-red">*</span>权重
            </label>
            <div class="layui-input-inline">
                <input type="text" id="sort" name="sort" required="" lay-verify="sort"
                       autocomplete="off" value="30" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="permission" class="layui-form-label">
                权限表示
            </label>
            <div class="layui-input-inline">
                <input type="text" id="permission" name="permission"
                       autocomplete="off" class="layui-input" value="">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否可见</label>
            <div class="layui-input-block">
                <input type="checkbox" checked="" name="isShow" lay-skin="switch" lay-filter="switchTest"
                       lay-text="no|off" value="1">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="remarks" class="layui-form-label">
                备注
            </label>
            <div class="layui-input-inline">
                <input type="text" id="remarks" lay-verify="remarks" name="remarks"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
            </label>
            <button class="layui-btn" lay-filter="add" lay-submit="">
                增加
            </button>45
        </div>
    </form>
</div>
<script>
    layui.use(['form', 'layer'], function () {
        $ = layui.jquery;
        var form = layui.form
            , layer = layui.layer;

        //监听指定开关
        form.on('switch(switchTest)', function (data) {
        });

        //自定义验证规则
        form.verify({
            remarks: function (value) {
                if (!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value) && value.length > 0) {
                    return '权限描述不能有特殊字符';
                }
                if (/(^\_)|(\__)|(\_+$)/.test(value)) {
                    return '权限描述首尾不能出现下划线\'_\'';
                }
                if (/^\d+\d+\d$/.test(value)) {
                    return '权限描述不能全为数字';
                }
            },
            name: function (value) { //value：表单的值、item：表单的DOM对象
                if (!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)) {
                    return '用户名不能有特殊字符';
                }
                if (/(^\_)|(\__)|(\_+$)/.test(value)) {
                    return '用户名首尾不能出现下划线\'_\'';
                }
                if (/^\d+\d+\d$/.test(value)) {
                    return '用户名不能全为数字';
                }
                if (value.length < 2) {
                    return '用户名不能小于2位';
                }
                if (value.length > 8) {
                    return '用户名不能大于8位';
                }
            },
            rule: function (value) {
                if (/^\d+\d+\d$/.test(value)) {
                    return '权限规则不能全为数字';
                }
                if (!/^[a-zA-Z0-9_]{0,}$/.test(value)) {
                    return '权限规则不能含有中文';
                }
            },
            sort: function (value) {
                if (!/^[0-9]+$/.test(value)) {
                    return '权限权重只能数字';
                }
            }
        });

        //监听提交
        form.on('submit(add)', function (data) {
            parent.location.replace(parent.location.href);
            var index = parent.layer.getFrameIndex(window.name);
            //关闭当前frame
            parent.layer.close(index);
            //发异步，把数据提交给php
            parent.layer.msg("增加成功", {icon: 6, time: 600});
        });
    });
</script>

</body>

</html>